package com.jnu.hospitalexamination.mapper;

import com.jnu.hospitalexamination.entity.Orders;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jnu.hospitalexamination.entity.vo.OrdersVO;
import com.jnu.hospitalexamination.entity.vo.UserOrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
* @author Nowonder
* @description 针对表【orders】的数据库操作Mapper
* @createDate 2024-07-21 23:01:59
* @Entity com.jnu.hospitalexamination.entity.Orders
*/
@Mapper
public interface OrdersMapper extends BaseMapper<Orders> {
    /**
     * 根据医院ID和日期获取当天预约人数
     * @param hpId 医院ID
     * @param orderDate 预约日期
     * @return 当天预约人数
     */
    @Select("SELECT COUNT(*) FROM orders WHERE hpId = #{hpId} AND orderDate = #{orderDate}")
    public Integer getOrderNum(@Param("hpId") Integer hpId, @Param("orderDate") LocalDate orderDate);


    /**
     * 根据用户ID获取用户预约列表
     * @param userId
     * @return 用户预约列表
     */
    @Select("SELECT o.*,sm.`name` FROM orders o " +
            "JOIN setmeal sm ON o.smId=sm.smId " +
            "WHERE o.userId=#{userId} " +
            "order by o.orderDate;")
    public List<OrdersVO> getOrderList(@Param("userId") Integer userId);

    /**
     * @return 返回体检报告列表
     */
    @Select("select o.orderId, u.phone, u.realName, u.sex, s.name as setmealname, h.name as hospitalname, o.orderDate " +
            "from users u join orders o on u.userId = o.userId " +
            "join hospital h on o.hpId = h.hpId " +
            "join setmeal s on o.smId = s.smId ")
    public List<UserOrderVO> getUserOrderList();


}




